<?php

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;

class Comment extends Model
{
    //软删除
    use SoftDelete;

    //会员关联
    public function members(){
        return $this->belongsTo('Member');
    }

    //文章关联
    public function articles(){
        return $this->belongsTo('Article');
    }

    public function add($data)
    {
        $validate = new \app\common\validate\Comment();
        if (!$validate->scene('add')->check($data)){
            return $validate->getError();
        }
        $result = $this->allowField(true)->save($data);
        if ($result){
            return 1;
        }else{
            return "评论失败";
        }
    }
}
